define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'roomcardcode/givediamond/index',
                    table: 'v_give_diamond',
                }
            });

            var table = $("#table");

        	table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'createtime',
                sortName: 'createtime',
                search: false,
                columns: [
                    [
                     	{field: 'uid', title: __('游戏ID')},
						{field: 'nickname', title: __('昵称'),searchable:false},
						{field: 'reason', title: __('账变类型'), searchList: {'1':'分享赠送', '2': '注册赠送', '3': '绑定邀请码', '4': '邮件赠送', '5': '实名认证'}},
						{field: 'num', title: __('房卡账变'),searchable:false},
                        {field: 'createtime', title: __('时间'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD HH:mm:ss"', style: 'min-width:90px;'},
                    ]
                ],
                
                onLoadSuccess: function (data) {
					if(data.map == 1){
						$("#statistics").html(
								'<a class="btn btn-danger">房卡总赠送：' + data.statistics.totalall + '</a>&nbsp;' 
								);
		            	$("#statistics").show();
		            }else{
						$("#statistics").html(
								'<a class="btn btn-danger">房卡总赠送：' + data.statistics.totalall + '</a>&nbsp;' 
								+ '<a class="btn btn-success">房卡月赠送：' + data.statistics.totalmonth + '</a>&nbsp;' 
								+ '<a class="btn btn-info">房卡周赠送：' + data.statistics.totalweek + '</a>&nbsp;' 
								+ '<a class="btn btn-warning">房卡今日赠送：' + data.statistics.totaltoday + '</a>&nbsp;' 
								);
	                	$("#statistics").show();
		            }

                }
                
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});